package com.example.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bean.GridViewBean;
import com.example.zhaccount.R;

public class GridViewAdapter extends BaseAdapter{
	private List<GridViewBean> list;
	private Context mContext;
	private GridViewBean gvBean;
	private Integer[] imgs;
	private String[] strs;
	
	public GridViewAdapter(List<GridViewBean> list, Context mContext) {
		super();
		this.list = list;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		if (list.size() > 0) {
			return list.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HolderView holder = null;
		if (convertView == null) {
			holder = new HolderView();
			convertView = LayoutInflater.from(mContext)
					.inflate(R.layout.gridview_item, null);
			holder.gv_img = (ImageView) convertView.findViewById(R.id.gvItem_img);
			holder.gv_tv = (TextView) convertView.findViewById(R.id.gvItem_type);
			convertView.setTag(holder);
		}else{
			holder = (HolderView) convertView.getTag();
		}
		gvBean = list.get(position);
		imgs = gvBean.getImgs();
		strs = gvBean.getTypes();
		String name = strs[position];
		int path = imgs[position];
		holder.gv_img.setImageResource(path);
		holder.gv_tv.setText(name);
		return convertView;
	}
	
	class HolderView{
		ImageView gv_img;
		TextView gv_tv;
	}

}
